const {resolve} = require('path');//处理文件路径的
const {CleanWebpackPlugin} = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack');
/* 
webpack静态模块打包器
常用的入口文件的名字 app.js main.js index.js

1.entry
2.output
3.loader
4.plugins
5.mode  development production


*/
module.exports = {
    // 入口
    entry:'./src/index.js',
    // 出口
    output:{
        filename:'./build.js',//打包输出的文件名字
        path:resolve(__dirname,'build')//D:\a-jinsi-courseware\1.class course\4.w2203A\6.webpack\webpack-2203-1\build\build.js
    },
    module: {
        rules: [
            {
                test: /\.css$/,
                use: [ 'style-loader', 'css-loader' ]
            },{
                test: /\.less$/,
                use: [ 'style-loader', 'css-loader' ,'less-loader']
            },{
                test:/\.(jpg|png|gif)$/,
                use: [
                    {
                      loader: 'url-loader',
                      options: {
                        limit: 8192,
                        name:'[hash:10].[ext]'
                      }
                    }
                  ]
            },{
                test:/\.html$/,
                use:{
                    loader: 'html-loader'
                }
            }
        ]
    },
    mode:'development',
    plugins:[
        new CleanWebpackPlugin(),
        new HtmlWebpackPlugin({
            template:'index.html',
            filename:'index.html',
            minify:{
                removeComments:true,
                collapseWhitespace:true
            }
        }),
        new webpack.HotModuleReplacementPlugin()
    ],
    devServer:{
        contentBase:resolve(__dirname,"build"),
        // 端口号
        port:3000,
        // 自动打开浏览器
        open:true
        // http://localhost:8080/
        // http://localhost:3000/
    },
    devtool:'inline-source-map'
}
